<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSkillsTable extends Migration
{
    /**
     * Run the migrations.
     * 职级对应工作内容表
     *
     * @return void
     */
    public function up()
    {
        Schema::create('skills', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->comment('职级名称');
            // $table->integer('organization_id')->unsigned()->comment('所属组织ID')->nullable();
            // $table->foreign('organization_id')->references('id')->on('organizations')->onDelete('set null');
            // $table->integer('department_id')->unsigned()->comment('所属部门ID')->nullable();
            // $table->foreign('department_id')->references('id')->on('departments')->onDelete('set null');
            // $table->integer('post_id')->unsigned()->comment('岗位等级id')->nullable();
            // $table->foreign('post_id')->references('id')->on('posts')->onDelete('set null');
            $table->text('remark')->comment('备注')->nullable();
            // $table->integer('number')->comment('职级人数')->nullable();
            $table->softDeletes();
            $table->timestamps();
            $table->unique(['name','deleted_at']);
        });

        Schema::create('skill_jobs', function (Blueprint $table) {
            $table->increments('id');
            $table->string('skill_id')->comment('职级id');
            $table->string('content')->comment('工作内容');
            $table->string('unit')->comment('任务单位')->default('㎡');
            $table->integer('number')->comment('任务量');
            $table->string('cycle_unit')->comment('周期单位')->nullable();
            $table->integer('cycle')->unsigned()->comment('任务周期')->nullable();
            $table->softDeletes();
            $table->timestamps();
        });

        Schema::create('post_skills', function (Blueprint $table) {
            //字段定义
            $table->increments('id');
            $table->integer('post_id')->unsigned()->comment('岗位id')->nullable();
            $table->foreign('post_id')->references('id')->on('posts')->onDelete('set null');
            $table->integer('skill_id')->unsigned()->comment('职级id')->nullable();
            $table->foreign('skill_id')->references('id')->on('skills')->onDelete('set null');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('post_skills');
        Schema::dropIfExists('skill_jobs');
        Schema::dropIfExists('skills');
    }
}
